package com.aurora.CETManagementSystem.controller;

import com.aurora.CETManagementSystem.mapper.AccountMapper;
import com.aurora.CETManagementSystem.mapper.NewsMapper;
import com.aurora.CETManagementSystem.mapper.TestLogMapper;
import com.aurora.CETManagementSystem.mapper.UserInfoMapper;
import com.aurora.CETManagementSystem.pojo.Account;
import com.aurora.CETManagementSystem.pojo.News;
import com.aurora.CETManagementSystem.pojo.TestLog;
import com.aurora.CETManagementSystem.pojo.UserInfo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class AdminController {

    @Resource
    AccountMapper accountMapper;

    @Resource
    UserInfoMapper userInfoMapper;

    @Resource
    TestLogMapper testLogMapper;

    @Resource
    NewsMapper newsMapper;



    //跳转到考试资讯管理页面
    @RequestMapping("/admin/toInfos")
    public String toInfos(){
        return "admin/infos";
    }

    //跳转到报名信息管理页面
    @RequestMapping("/admin/toSignups")
    public String toSignups(Model model){
        List<TestLog> testLogs = testLogMapper.selectList(null);
        model.addAttribute("testLogs",testLogs);
        return "admin/signups";
    }


    //跳转到学生管理页面
    @RequestMapping("/admin/toStudents")
    public String toStudents(Model model){

        List<UserInfo> studentlist = userInfoMapper.selectList(new QueryWrapper<UserInfo>().isNotNull("stu_num"));
        model.addAttribute("studentlist",studentlist);
        return "admin/students";
    }

    //跳转到账号管理页面
    @RequestMapping("/admin/toAccounts")
    public String toAccounts(Model model){
        HashMap<String, Object> map = new HashMap<>();
        map.put("permission", "student");

        List<Account> stuaccounts = accountMapper.selectByMap(map);

        model.addAttribute("stuaccounts",stuaccounts);

        return "admin/accounts";
    }


    /**
     * 跳转到添加资讯页面
     * @return
     */
    @RequestMapping("/admin/news/toAdd")
    public String toAddNews(){
        return "admin/news_add";
    }

    /**
     * 跳转到资讯管理页面
     * @return
     */
   @GetMapping("/admin/news")
   public String toNews(Model model) {
       List<News> news = newsMapper.selectList(null);
       model.addAttribute("news", news);
       return "admin/news_list";

   }














}

